package net.randomice.emf.observables.demo.extlibrary.persons.observables;

import net.randomice.emf.observables.demo.extlibrary.Addressable;
import net.randomice.emf.observables.demo.extlibrary.ExtlibraryPackage;
import net.randomice.emf.observables.demo.extlibrary.persons.Person;
import net.randomice.emf.observables.demo.extlibrary.persons.PersonsPackage;
import org.eclipse.core.databinding.observable.map.IObservableMap;
import org.eclipse.core.databinding.observable.set.IObservableSet;
import org.eclipse.core.runtime.Assert;
import org.eclipse.emf.databinding.EMFObservables;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;

/**
 * An Observable list wrapper for {@link Person}
 * @generated
 */
public class PersonOS {
	public final IObservableSet o;

	public PersonOS(IObservableSet observableSet) {
		Object type = observableSet.getElementType();
		if (type instanceof EReference) {
			type = ((EReference) type).getEType().getInstanceClass();
		}
		Assert.isTrue(null == type || Person.class.equals(type));
		o = observableSet;
	}

	public IObservableMap getMapFeature(EStructuralFeature feature) {
		if (ExtlibraryPackage.Literals.ADDRESSABLE__ADDRESS.equals(feature)) {
			return getAddress();
		}
		if (PersonsPackage.Literals.PERSON__FIRST_NAME.equals(feature)) {
			return getFirstName();
		}
		if (PersonsPackage.Literals.PERSON__LAST_NAME.equals(feature)) {
			return getLastName();
		}
		throw new UnsupportedOperationException("Feature " + feature
				+ " not supported!");
	}

	// features from type Addressable

	private IObservableMap address = null;
	public IObservableMap getAddress() {
		if (null == address) {
			address = EMFObservables.observeMap(o,
					ExtlibraryPackage.Literals.ADDRESSABLE__ADDRESS);
		}
		return address;
	}

	// features from type Person

	private IObservableMap firstName = null;
	public IObservableMap getFirstName() {
		if (null == firstName) {
			firstName = EMFObservables.observeMap(o,
					PersonsPackage.Literals.PERSON__FIRST_NAME);
		}
		return firstName;
	}

	private IObservableMap lastName = null;
	public IObservableMap getLastName() {
		if (null == lastName) {
			lastName = EMFObservables.observeMap(o,
					PersonsPackage.Literals.PERSON__LAST_NAME);
		}
		return lastName;
	}

}
